@use "sass:math";

// 清除浮动
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

// 文本溢出省略
@mixin ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// 多行文本溢出省略
@mixin multi-ellipsis($line: 2) {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: $line;
  overflow: hidden;
}

// flex 布局
@mixin flex($direction: row, $justify: center, $align: center) {
  display: flex;
  flex-direction: $direction;
  justify-content: $justify;
  align-items: $align;
}

// 绝对定位居中
@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 固定宽高比
@mixin aspect-ratio($width: 1, $height: 1) {
  position: relative;
  &::before {
    content: '';
    display: block;
    padding-top: math.div($height, $width) * 100%;
  }
  > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}

// 响应式断点
@mixin respond-to($breakpoint) {
  @if $breakpoint == 'phone' {
    @media only screen and (max-width: 37.5em) { @content }; // 600px
  }
  @if $breakpoint == 'tablet' {
    @media only screen and (max-width: 56.25em) { @content }; // 900px
  }
  @if $breakpoint == 'desktop' {
    @media only screen and (max-width: 75em) { @content }; // 1200px
  }
  @if $breakpoint == 'big-desktop' {
    @media only screen and (min-width: 112.5em) { @content }; // 1800px
  }
}

// 滚动条样式
@mixin scrollbar {
  &::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  
  &::-webkit-scrollbar-track {
    background: $background-color-base;
    border-radius: 3px;
  }
  
  &::-webkit-scrollbar-thumb {
    background: $text-secondary;
    border-radius: 3px;
    
    &:hover {
      background: $text-regular;
    }
  }
}

// 禁用文本选择
@mixin no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

// 渐变背景
@mixin gradient($start-color, $end-color, $direction: to right) {
  background-image: linear-gradient($direction, $start-color, $end-color);
} 